/* Project am_T01
Infrared controller PIC12F675
*/

//#include <pic.h>
#define _LEGACY_HEADERS // 旧バージョンのプログラムで記述
#include <htc.h> // 旧バージョンのプログラムで記述


__CONFIG(
INTIO
& UNPROTECT
& BORDIS
& MCLRDIS
& WDTDIS
& PWRTEN
);

__IDLOC(F675);

#define SW1 GPIO0
#define SW2 GPIO1
#define SW3 GPIO2
#define SW4 GPIO3
#define OUT GPIO5

#define RH 100
#define RL 100
#define D1H 50
#define D1L 50
#define D0H 20
#define D0L 80
#define N 4


const unsigned char sig1[N] = {
1,0,0,0
};
const unsigned char sig2[N] = {
0,1,0,0
};
const unsigned char sig3[N] = {
0,0,1,0
};
const unsigned char sig4[N] = {
0,0,0,1
};



void main(void){

unsigned char i, tH, tL;

CMCON = 0b00000111;
ANSEL = 0b00000000;
GPIO = 0;
TRISIO = 0b00001111;
OPTION = 0b10000100;

SW1 = 0; SW2 = 0; SW3 = 0; SW4 = 0;



while(1){

while(SW1 && SW2 && SW3 && SW4);

OUT = 0;

TMR0 = 0;
while(TMR0 < 255);
TMR0 = 0;
while(TMR0 < 58);
TMR0 = 0;
while(TMR0 < 255);
TMR0 = 0;
while(TMR0 < 58);
TMR0 = 0;



//Reader

TMR0 = 0;
while(TMR0 < RH) OUT = 1;

TMR0 = 0;
while(TMR0 < RL) OUT = 0;



//Data


if(SW1 = 1){

for(i = 0; i < N; i++){

if(sig1[i]) {
tH = D1H; tL = D1L;
}
else {
tH = D0H; tL = D0L;
}

TMR0 = 0;
while(TMR0 < tH) OUT = 1;

TMR0 = 0;
while(TMR0 < tL) OUT = 0;
}
}



if(SW2 = 1){

for(i = 0; i < N; i++){

if(sig2[i]) {
tH = D1H; tL = D1L;
}
else {
tH = D0H; tL = D0L;
}

TMR0 = 0;
while(TMR0 < tH) OUT = 1;

TMR0 = 0;
while(TMR0 < tL) OUT = 0;
}
}



if(SW3 = 1){

for(i = 0; i < N; i++){

if(sig3[i]) {
tH = D1H; tL = D1L;
}
else {
tH = D0H; tL = D0L;
}

TMR0 = 0;
while(TMR0 < tH) OUT = 1;

TMR0 = 0;
while(TMR0 < tL) OUT = 0;
}
}


if(SW4 = 1){

for(i = 0; i < N; i++){

if(sig4[i]) {
tH = D1H; tL = D1L;
}
else {
tH = D0H; tL = D0L;
}

TMR0 = 0;
while(TMR0 < tH) OUT = 1;

TMR0 = 0;
while(TMR0 < tL) OUT = 0;
}
}


}
}


             戻る